'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    ctx.body = 'hi, egg';
  }
  //渲染登录界面
  async login() {
    await this.ctx.render('login');
  }

  async register() {
    const { username } = this.ctx.query;
    console.log(this.ctx.query);
    if(username === '') {
      return this.ctx.body = { result: 1, msg: 'username不能为空' };
    }
    this.ctx.session.username = username;
    this.ctx.body = { result: 0 };
  }
  //渲染聊天室界面
  async chatroom() {
    await this.ctx.render('/chatroom',{
      username: this.ctx.session.username
    })
  }
}

module.exports = HomeController;
